package com.facetoface.wxapi;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import com.tencent.mm.opensdk.modelbase.BaseReq;
import com.tencent.mm.opensdk.modelbase.BaseResp;
import com.tencent.mm.opensdk.openapi.IWXAPI;
import com.tencent.mm.opensdk.openapi.IWXAPIEventHandler;
import com.tencent.mm.opensdk.openapi.WXAPIFactory;
import com.facetoface.WeChatManager;

public class WXPayEntryActivity extends Activity implements IWXAPIEventHandler {
    
    private IWXAPI api;
    
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        
        // 初始化微信API
        api = WXAPIFactory.createWXAPI(this, WeChatManager.getAppId(), false);
        api.handleIntent(getIntent(), this);
    }
    
    @Override
    protected void onNewIntent(Intent intent) {
        super.onNewIntent(intent);
        setIntent(intent);
        api.handleIntent(intent, this);
    }
    
    @Override
    public void onReq(BaseReq req) {
        // 微信发送请求到第三方应用时回调
        finish();
    }
    
    @Override
    public void onResp(BaseResp resp) {
        // 第三方应用发送请求到微信，微信返回的响应结果回调
        WeChatManager.handlePayResponse(resp);
        finish();
    }
}